<?php
$page = $this->page;
$ajaxUrl = $this->url(array('module' => 'bid', 'controller' => 'ajax', 'action' => 'product-list'), 'default', true);
$this->headScript()->appendScript(";(function(W, D, $) {
$(D).ready(function() {
    var currentPage = ".($page+1).";
    var ajaxUrl = '".$ajaxUrl."' + '/page/' + currentPage;
	$('#itemContainer').masonry({
		'columnWidth' 		: 220
		, 'itemSelector'	: '.itemDetail'
		, 'gutter'			: 12
	});
		
	$(W).scroll(function() {
		if ($(W).scrollTop() + $(W).height() == $(D).height()) {
			if ($('#itemContainer').length == 1 && !$('#itemContainer').hasClass('ajax-loading')) {
				$('#itemContainer').addClass('ajax-loading');
				$.ajax({
					'url': ajaxUrl
					, 'dataType': 'html'
					, 'success': function(data) {
						var holder = $('#ajax-content-holder');
						if (holder.length == 0) {
							holder = $('<div/>', {
								'id': 'ajax-content-holder'
								, 'css': {
									'width': '1px'
									, 'height': '1px'
									, 'overflow': 'hidden'
								}
							}).appendTo('body');
						}
						holder.append(data);
						var items = holder.find('.itemDetail');
						$('#itemContainer').append(items).masonry('appended', items);
                        currentPage++;
						ajaxUrl = '".$ajaxUrl."' + '/page/' + currentPage;
						$('#itemContainer').removeClass('ajax-loading');
					}
				});
			}
		}
	});
});
})(window, document, jQuery);", $type = "text/javascript");
?>
<div id="itemContainer" class="itemContainer">
<?php
if(count($this->items)) {
    foreach($this->items as $item) {
        echo $this->partial('partials/home-item.phtml', array('item' => $item));
    }
}
?>
</div>